package 牛客题霸;

public class 删除有序链表中重复的元素II {

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode dum = new ListNode(-1);
        ListNode cur = dum;
        while (head != null) {
            if (head.next == null || head.val != head.next.val) {
                cur.next = head;
                cur = cur.next;
            }
            while (head.next != null && head.val == head.next.val) {
                head = head.next;
            }
            head = head.next;
        }
        cur.next = null;
        return dum.next;
    }

    public static void main(String[] args) {

    }

    public static class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
}
